import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { STColumn, STComponent } from '@delon/abc';
import { GridComponent, PopdetailComponent, HttpService, SupDic } from 'lbf';
import { SFSchema, SFComponent, SFDateWidgetSchema } from '@delon/form';
import { NzMessageService } from 'ng-zorro-antd';
import {XtgnJztemplateComponent} from '../jztemplate/jztemplate.component';

@Component({
  selector: 'app-xtgn-mzcs',
  templateUrl: './mzcs.component.html',
  styleUrls: ['./mzcs.component.less']
})
export class XtgnMzcsComponent implements OnInit {
  isJzxxVisible = false
  params = {sname: 'JCPM_mzcspm',form: {jsny: {SYEAR: new Date().getFullYear()+"",SMONTH: "0"+(new Date().getMonth()+1)}}}
  jzxxparams = {sname: 'JCPM_jzxx',form: {}}
  searchSchema: SFSchema = {
    properties: {
      jsny: {
        type: 'string',
        title: '结算年月',
        format: 'month',
        default: new Date().getFullYear()+"-0"+(new Date().getMonth()+1)
      },
      AAE140: {
        type: 'string',
        title: '险种',
        ui: {
          widget: 'select',
          allowClear: true,
          width: 200
        },
        enum: this.supdic.getSFDic('AAE140')
      }
    }
  };
  @ViewChild('st', { static: false }) st: GridComponent;
  @ViewChild('jzxxst', { static: false }) jzxxst: GridComponent;
  @ViewChild('sf', { static: false }) sf: SFComponent;

  columns: STColumn[] = [
    { title: '姓名', index: 'AAC003' },
    { title: '身份证',index: 'AAC002' },
    { title: '性别',index: 'AAC004' ,type: 'tag',
      tag: {
        1: { text: '男', color: 'green' },
        2: { text: '女', color: 'red' }
      },
    },
    { title: '所属医共体',index: 'AKE500',dic: 'AKE500',width: 100 },
    { title: '总费用',index: 'AKC046', type: 'currency' },
    { title: '医保费用',index: 'AKC048', type: 'currency'},
    { title: '基金支出',index: 'AKC370', type: 'currency'},
    { title: '就诊次数',index: 'VAL',type: 'number'},
    {
      title: '操作区',
      buttons: [
         { text: '就诊信息', click: (record)=> 
              {this.isJzxxVisible = true
               this.jzxxparams.form = {AAC001: record.AAC001,AKE500:record.AKE500,AAE070:record.SYEAR+'-'+record.SMONTH}
               this.jzxxst.reload(this.jzxxparams.form)
         }},
      ]
    }
  ];

  jzxxcolumns: STColumn[] = [
    { title: '姓名', index: 'AAC003' },
    { title: '身份证',index: 'AAC002' },
    { title: '性别',index: 'AAC004' ,type: 'tag',
      tag: {
        1: { text: '男', color: 'green' },
        2: { text: '女', color: 'red' }
      },
    },
    { title: '所属医共体',index: 'AKE500',dic: 'AKE500',width: 100 },
    { title: '就诊机构',index: 'AKB002' },
    { title: '机构类别',index: 'AKB025', dic: 'AKB025', width: 100  },
    { title: '结算日期',index: 'AAE070' },
    { title: '就诊日期',index: 'AKC041' },
    { title: '总费用', index: 'AKC046', type: 'currency' },
    { title: '医保费用', index: 'AKC048', type: 'currency' },
    { title: '基金支出', index: 'AKC270', type: 'currency' },
    { title: '个人现金', index: 'AKC276', type: 'currency' },
    { title: '结算区域', index: 'AKE056', dic: 'AKE056', width: 100  },
    { title: '就诊科室', index: 'BKE005' },
    { title: '社保编号', index: 'AAC001' },
    {
      title: '操作区',
      buttons: [
         { text: '详情',
            type: 'modal',
            modal: {
              component: XtgnJztemplateComponent,
            }
            ,
            click: (_record) => {}
       }
      ]
    }
  ];

  constructor(private modal: ModalHelper,
    public msgSrv: NzMessageService,
    private lbservice: HttpService,
    private supdic: SupDic
  ) { }

  ngOnInit() { }

  search(){ 
    console.log(this.sf.value)
    if(this.sf.value.hasOwnProperty('jsny') && this.sf.value.jsny !== ""){
      const time = {SYEAR: this.sf.value.jsny.split("-")[0],SMONTH: this.sf.value.jsny.split("-")[1]}
      this.sf.value.jsny = time;
      console.log(this.sf.value)
    }
    this.st.reload(this.sf.value)
  }

  reset(){
    this.st.reload(this.params.form);
    this.sf.refreshSchema();
  }

  handleCancelJzxx(){
    this.isJzxxVisible = false
  }
}
